home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODF-Interest Archive / April 96 / Re Offscreen bitmaps & switchi < prev    next >
Encoding:
Internet Message Format  |  1996-12-03  |  2.8 KB  |  [TEXT/ttxt]

  1. Subject:     Re: Offscreen bitmaps & switching between two contexts
  2. Sent:        4/15/96 5:01 PM
  3. Received:    4/15/96 5:11 PM
  4. From:        Henri Lamiraux, lamiraux@apple.com
  5. Reply-To:    ODF-Interest@CILabs.ORG
  6. To:          OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
  7.  
  8. >Greetings,
  9. >I have created a render class that contains an offscreen bitmap created
  10. >with the following code:
  11. >
  12. >        fOffScreenBitmap = FW_NEW(FW_PBitmap,
  13. >                (fOffScreenRect.right.AsInt(),
  14. >                fOffScreenRect.bottom.AsInt(), 0));
  15. >
  16. >fOffScreenBitmap is a member variable of my class defined as FW_PBitmap*.
  17. >
  18. >I want to be able to create and maintain a FW_CBitmapContext and store it
  19. >in my class.  Then, when I want to render to the offscreen, I'll save the
  20. >current context and then switch the context to my offscreen bitmap context.
  21. >
  22. >FW_CBitmapContext is an auto destruct class and seems to perform its magic
  23. >(i.e. switch the context etc.) when the class is created. How do I create
  24. >one of these, save the current context, switch the context and switch the
  25. >context back once I am done?
  26. >
  27. >All of the examples I have seen create this class as a temporary variable
  28. >immediately before doing their rendering. This is not suitable for what I
  29. >am trying to accomplish. I need to be able to create the context in the
  30. >initialize method of my class, set it in other methods of my class and
  31. >delete it in the destructor of my class.
  32. >
  33. >BTW, what is the proper way to dispose of an object created with the FW_NEW
  34. >macro? Since I only create one instance of the class I currently do a
  35. >"delete fOffScreenBitmap". Is this the correct way to handle this?
  36. >
  37. >Thanks for your help,
  38. >Nolan Larsen
  39. >Digital Harbor
  40.  
  41. 1)
  42.  
  43. FW_PXXXX object should be defined on the stack. FW_PXXX are already 
  44. pointers (smart pointers). o You should write something like that:
  45.  
  46. class CMyClass
  47. {
  48. public:
  49.   CMyClass();
  50.   virtual ~CMyClass();
  51.   ....
  52.  
  53. private:
  54.   FW_PBitmap fMyBitmap;   // and not FW_PBitmap*. Default constructor 
  55. creates a "NULL" Bitmap
  56. };
  57.  
  58.  
  59. CMyClass::CMyClass()
  60. {
  61.   FW_PBitmap aBitmap(fOffScreenRect.right.AsInt(), 
  62. fOffScreenRect.bottom.AsInt(), 0);
  63.   fMyBitmap = aBitmap;
  64. }
  65.  
  66. CMyClass::~CMyClass()
  67. {
  68.    // Don't do anything. Will automatically delete the bitmap
  69. }
  70.  
  71.  
  72. 2)
  73.  
  74. FW_CBitmapContext should always be created on the stack. Trying to store 
  75. a pointer to a FW_CBitmapContext is a bad idea. Context should only be 
  76. created when needed and released immediatly.
  77.  
  78. 3)
  79.  
  80. Using delete to delete objects created with FW_NEW is fine.
  81.  
  82. .......................................................................
  83.  Henri Lamiraux                                      lamiraux@apple.com
  84.  Apple Computer, Inc.                 OpenDoc(tm) Development Framework
  85. .......................................................................
  86.  
  87.  
  88.